<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教练管理列表</title>

    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../layui/lay/modules/laydate.js"></script>
    <link href="../../layui/css/modules/laydate/default/laydate.css"  rel="stylesheet">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->

</head>
<body>

<!--主体内容-->
<div class="layui-fluid">
    <div class="layui-card content-wrap">

        <form class="layui-form layui-form-pane" action="">
            <div class="layui-row  layui-col-space15">
                <div class="layui-col-sm4">
                    <label class="layui-form-label">教练列表</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" placeholder="请输入教练姓名和证件号码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <label class="layui-form-label">培训车型</label>
                    <div class="layui-input-block">
                        <select id="trainCrtype">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <label class="layui-form-label">时间类型</label>
                    <div class="layui-input-block">
                        <select id="timeType">
                            <option value="">请选择</option>
                            <option value="1">创建时间</option>
                            <option value="2">修改时间</option>
                        </select>
                    </div>
                </div>

            </div>

            <div class="layui-row layui-col-space15 layui-form-item">

                <div class="layui-col-sm4">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" autocomplete="off"  id="stime" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" autocomplete="off" id="etime" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <button class="layui-btn delete_btn" data-type="reloadClean"><i class="layui-icon layui-icon-delete"></i>清空</button>
                   <!-- <button class="layui-btn add_btn" data-type="reload" id="searchBtn"><i class="layui-icon layui-icon-search"></i>搜索</button>-->
                    <a class="layui-btn add_btn" data-type="reload" id="searchBtn"><i class="layui-icon layui-icon-search"></i>搜索</a>

                </div>
            </div>
        </form>
        <div class="layui-form-item">
            <div>
                <button class="layui-btn ax-btn add_btn"     id="add"><i class="layui-icon layui-icon-add-circle"></i>增加</button>
                <button class="layui-btn ax-btn change_btn"  id="update"><i class="layui-icon layui-icon-edit"></i>编辑</button>
                <button class="layui-btn ax-btn delete_btn"  id="delete"><i class="layui-icon layui-icon-delete"></i>删除</button>
            </div>
        </div>
        <table class="layui-hide" id="activeListTbale" lay-filter="active"></table>
        <script type="text/html" id="imgTpl">
            {{#   <span style="color: #007cff;" onclick=show('+d+')>查看图片</span> }}
        </script>
    </div>
</div>
<!--主体内容-->

</body>

<script>
    $(function () {
        ax.post({
            url: schoolWebUrl + '/api/dict/getDict',
            contentType: "application/x-www-form-urlencoded",
            data:{"code":"car"},
            success: function (r) {
                var data=r.data;
                for(var i=0;i<data.length;i++){
                    $("#trainCrtype").append(' <option value='+data[i].id+'>'+data[i].code+" : "+data[i].name+'</option>');
                }
            },
        });
    });

    var table;
    var tableIns;
    layui.use(['table', 'form', 'laydate', 'layer','element'], function () {
        table = layui.table;
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer;

        tableIns = ax.VTable({
            elem: '#activeListTbale',
            url: schoolWebUrl+'/api/coach/list',
            id: 'testReload',
            toolbar: '#optToolbar',
            cols: [[
                {type: 'checkbox',fixed: 'left'},
                {field:'序列号', width:80,title: '序列号',type:'numbers'},
                {field: 'coachNumber',width: 100,title: '教练编号',},
                {field: 'name',width: 80,title: '姓名' },
                {field: 'sexName',width: 60,title: '性别'},
                {field: 'idnum', width: 180,title: '证件号码' },
                {field: 'phone', width: 120, title: '手机号码' },
                {field: 'trainCartype',width: 160, title: '培训车型'},
                {field: 'subject',width: 160, title: '培训科目',templet: '#stateTpl'},
                {field: 'coachHead',width: 160,title: '教练头像',templet: '#head',event:'head'},
                {field: 'wechat',width: 120,title: '微信号',templet: '#stateTpl'},
                {field: 'updated', width: 160,title: '修改时间'},
                {field: 'created',width: 160,title: '创建时间'}
                ]],
            });

        //日期时间选择器
        laydate.render({
            elem: '#stime'
            ,type: 'datetime'
        });
        //日期时间选择器
        laydate.render({
            elem: '#etime'
            ,type: 'datetime'
        });
        var $ = layui.$, coach = {
            reload: function(){
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        trainCrtype: $("#trainCrtype").val(),
                        stime: $("#stime").val(),
                        etime: $("#etime").val(),
                        timeType: $("#timeType").val(),
                        coach: $("#name").val()
                    }
                });
            }
        };
        $('#delete').on('click', function(){
            //获取选中的数据
            layer.confirm('真的删除这行数据么?', function(index){
                var checkStatus = table.checkStatus('testReload'),data = checkStatus.data;
                if(data.length>1){
                    layer.close(index);
                    layer.alert("最多选择一条数据");
                    return;
                }
                var postData={"id":data[0].id};
                ax.post({
                    type: 'POST',
                    url: schoolWebUrl+'/api/coach/delete',
                    contentType: "application/x-www-form-urlencoded",
                    data: postData,
                    success: function (r) {
                        layer.close(index);
                        layer.alert(r.message);
                        reset();

                    },
                });
            });
        });
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            coach[type] ? coach[type].call(this) : '';
        });
        //新增教练
        $('#add').on('click', function(){
            top.layer.open({
                title:"新增教练",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['100%', '100%'],
                content: './school/school/coachAdd.html'
            });
        });
        //修改教练
        $('#update').on('click', function(){
            var checkStatus = table.checkStatus('testReload'),data = checkStatus.data;
            if(data.length>1){
                layer.close(index);
                layer.alert("最多选择一条数据");
                return;
            }
            top.layer.open({
                title:"修改教练",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['100%', '100%'],
                content: './school/school/coachEdit.html?id='+data[0].id
            });
        });

    });
//重置页面
function reset() {
        //执行重载
        table.reload('testReload', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {
            }
    });
}

</script>
</html>